package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.utils.R;
import com.qf.vo.UserVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/10
 */
@RestController
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 根据id 查询用户
     * @param id
     * @return
     */
    @GetMapping("/findUser")
    public R<User> findUserById(int id) {
        User user = userService.findUserById(id);
        return R.ok(user);
    }

    /**
     * 查询全部用户
     * @return
     */
    @GetMapping("/findUserAll")
    public R<List<User>> findUserAll(){
        List<User> userAll = userService.findUserAll();
        return R.ok(userAll);
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public R<User> login(@RequestBody User user){
        User login = userService.login(user);
        return R.ok(login);
    }

    @PostMapping("/addUser")
    public R addUser(User user){
        int i = userService.addUser(user);
        return R.ok(i);
    }

    @GetMapping("/updateUser")
    public R<?> updateUser(User user){
        return R.ok(userService.updateUser(user));
    }

    @GetMapping("/userWithOrder/{id}")
    public R<UserVo> findUserWithOrderById(@PathVariable int id){
        return R.ok(userService.findUserWithOrderById(id));
    }
}
